{"id":463,"date":"2017-11-01T08:05:29","date_gmt":"2017-11-01T08:05:29","guid":{"rendered":"http:\/\/buklijas.info\/blog\/?p=463"},"modified":"2018-12-15T10:57:53","modified_gmt":"2018-12-15T10:57:53","slug":"controlling-nec-display-python-nec-pd-sdk","status":"publish","type":"post","link":"http:\/\/buklijas.info\/blog\/2017\/11\/01\/controlling-nec-display-python-nec-pd-sdk\/","title":{"rendered":"Controlling NEC display from Python with nec-pd-sdk"},"content":{"rendered":"
Update on:<\/strong> 07.03.2018 Published on:<\/strong> 01.11.2017<\/p>\n I was responsible for maintenance of one spectacular 17 meters tall audio\/video system on a cruise ship.<\/p>\n The system had 34 NEC X551UN screens<\/a> among other components.<\/p>\n <\/p>\n Behind each screen, there is a SDI-to-DVI converter.<\/p>\n If a picture on the screen was black, usually there was some problem with SDI-to-DVI converter, mostly power supply was broken.<\/p>\n Or NEC screen was broken, but I never had it in practice.<\/p>\n But, also there was one special screen, it was black from time to time<\/strong>.<\/p>\n After restart mostly fine, and SDI-to-DVI converter was fine.<\/p>\n After one month of troubleshooting, I have come to the conclusion that problem is with NEC screen.<\/p>\n It just got stuck every few days<\/strong> (sometimes every second day, some time was fine for a week), and simple restart (sometimes of 5 seconds and sometimes of 5 minutes) would solve issue till next time.<\/p>\n I also know that when there is a black picture on this screen, then screen diagnostic was “No signal.”<\/p>\n <\/p>\n I have come to the conclusion that the following code could solve the problem:<\/p>\n And then to run this code on a schedule, like every hour.<\/p>\n NEC have two software applications for managing their products.<\/p>\n First is PD Comms Tool<\/a>, you can remotely get and set all values to a screen.<\/p>\n It also has a scripting language<\/strong>.<\/p>\n I have used it for setting scheduler for all 34 screens and change of time.<\/p>\n It is much faster than manually doing it for each screen.<\/p>\n The second one is NaViSet Administrator 2<\/a> it is much more powerful than “PD Comms Tool”.<\/p>\n It can be used for monitoring all your NEC screens and also some additional equipment (like projectors and Windows PC)<\/p>\n It also has a visual scripting language<\/strong> where you can set and get multiple parameters according to some condition.<\/p>\n And then you also can set specific scheduler for each script.<\/p>\n I could have used this tool for my problem, but there was just one problem, it did not have sleep\/pause command.<\/p>\n I know that existing NEC software is communicating with the screen via TCP\/IP.<\/p>\n Full protocol documentation is at http:\/\/www.necdisplay.com\/documents\/UserManuals\/External_Control_P.V.X-series.pdf<\/a>, but I was not so eager to write custom TCP\/IP packets.<\/p>\n I wanted something more readable and simple<\/strong>.<\/p>\n I googled “NEC python” and found about nec-pd-sdk<\/a>, what is python SDK for NEC screens.<\/p>\n There is no textual documentation, but there are few examples<\/a>.<\/p>\n Most useful for me was test_routines_example.py<\/a>, it is showing how to get every parameter.<\/p>\n The command for turning screen ON and OFF<\/strong> was found in source code<\/a>.<\/p>\n Here is the code:<\/p>\n When I was investigating NaViSet Administrator 2<\/a> for my use-case.<\/p>\n I contacted NEC support, to ask can them can I use it for this purpose.<\/p>\n They told me not and suggested to use TCP\/IP External_Control<\/a>.<\/p>\n So, even support from NEC does not know that they have NEC python SDK<\/a>.<\/p>\n
\nUpdated version available on Twilio blog<\/a>.<\/p>\nConclusion<\/h4>\n
pip install nec-pd-sdk<\/code><\/p>\n
My Story<\/h4>\n
Special NEC screen<\/h4>\n
\nif diagnostic_of_screen is \"no_signal\" is True;\n turn screen OFF\n wait 5 minutes\n turn screen ON \n<\/pre>\n
Existing NEC software<\/h4>\n
Design<\/h4>\n
Code for turning NEC screen ON and OFF<\/h4>\n
\nfrom __future__ import print_function\nfrom nec_pd_sdk.nec_pd_sdk import NECPD\nfrom nec_pd_sdk.protocol import PDError\nfrom nec_pd_sdk.constants import PD_POWER_STATES\nimport time # for sleep\nimport sys\n\n\ndef get_screen_state(pd):\n state = pd.command_power_status_read()\n text_list = pd.helper_self_diagnosis_status_text()\n return {'status': state, 'diagnosis': text_list}\n\n\ndef main():\n try:\n pd = NECPD.open('192.168.1.52')\n\n monitor_id = 1\n pd.helper_set_destination_monitor_id(monitor_id)\n\n try:\n screen_state = get_screen_state(pd)\n\n # 'Normal; ' 'No signal; '\n if screen_state['diagnosis'] == 'No signal; ':\n \n # OFF\n pd.command_power_status_set(PD_POWER_STATES['Off'])\n\n # pause\n time.sleep(5 * 60) # 5 minutes\n\n # ON\n pd.command_power_status_set(PD_POWER_STATES['On']) # 1\n\n finally:\n # make sure to always close\n pd.close()\n\n except PDError as msg:\n print(\"PDError:\", msg)\n return\n\n\nif __name__ == '__main__':\n main()\n\n# https:\/\/github.com\/pyinstaller\/pyinstaller\/issues\/1687\nsys.exit() \n<\/pre>\n
Last Words<\/h4>\n