Good morning,
I have a little issue with my LabWindows program, I will explain it in the following lines.
I did a test bench with an Arduino Mega to perform 10 tests in a specific DUT and I control the entire system with a LabWindows GUI. Every single communication is ok, I send (from LabWindows to Arduino) and I receive (from Arduino to LabWindows) the correct value.
The problem is when Arduino makes test: if I want to stop the tests list in any time with LabWindows GUI (Command Button), I can't do it because the interface is freezed, so I can't push any button to click in case of emergency. I always wait the end of the tests to interact with the program.
HW parts:
- Arduino Mega;
- Cable TTL-234X-5V (with drivers installed);
- HP ZBook 15v G5.
SW used:
- Windows 10;
- Arduino IDE 1.8.9;
- LabWindows/CVI v17.0.0 (2017).
Configuration:
GND (Arduino Mega) --> Black wire GND (TTL-234X-5V);
Digital19 RX1 (Arduino Mega) --> Orange wire TXD (TTL-234X-5V);
Digital18 TX1 (Arduino Mega) --> Yellow wire RXD (TTL-234X-5V).
Windows S.O. recognizes the configuration above in "USB Serial Port (COM3)".
The code that I used is the following (I simplified it):
COMMAND BUTTON to start tests list
int CVICALLBACK testListArduino (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_LEFT_CLICK: iTest = 1; do { if(iTest == 1) { firstTest(panel, info); if(iRS232Error != 0) iTest = 11; else iTest = 2; } else if(iTest == 2) { secondTest(panel, info); if(iRS232Error != 0) iTest = 11; else iTest = 3; } ... else if(iTest == 10) { tenTest(panel, info); iTest = 11; } }while(iTest < 11); break; } return 0; }
FUNCTION TEST (for example first)
... #define READTERM 10 int iPortArduino = 3; ... void firstTest(int panel, char info[LENGTH_INFO]) { dResult[0] = 0; dResult[1] = 0; dResult[2] = 0; SetCtrlVal(panel, PanelMain_STRING, "A"); // Letter A in Arduino is the first test case DisableBreakOnLibraryErrors (); iRS232Error = OpenComConfig (iPortArduino, "", 9600, 0, 8, 1, 512, 512); // Open port COM EnableBreakOnLibraryErrors (); if(iRS232Error != 0) // If the COM is incorrect { MessagePopup("Error","Error."); dResult[0] = -1; dResult[1] = -1; dResult[2] = -1; return; } SetComTime (iPortArduino, 10); SetCTSMode (iPortArduino, LWRS_HWHANDSHAKE_OFF); FlushInQ(iPortArduino); GetCtrlVal(panel, PanelMain_STRING, info); // info = 'A' Delay(1); // I used this to delay serial port ComWrt(iPortArduino, info, strlen(info)); // Send A to Arduino inqlen = GetInQLen (iPortArduino); bytes_read = ComRdTerm (iPortArduino, read_data, 10, READTERM); // Take result1 from arduino script with Serial1.println(...); CopyString (tbox_read_data, 0, read_data, 0, bytes_read); dResult[0] = atof(&tbox_read_data); bytes_read = ComRdTerm (iPortArduino, read_data, 10, READTERM); // Take result2 from arduino script with Serial1.println(...); CopyString (tbox_read_data, 0, read_data, 0, bytes_read); dResult[1] = atof(&tbox_read_data); bytes_read = ComRdTerm (iPortArduino, read_data, 10, READTERM); // Take result3 from arduino script with Serial1.println(...); CopyString (tbox_read_data, 0, read_data, 0, bytes_read); dResult[2] = atof(&tbox_read_data); FlushInQ(iPortArduino); CloseCom (iPortArduino); // Close port COM return; }
Do you have any ideas to create a stop button for emergency in CVI? Or, with this managing, is impossible (i.e. maybe OpenComConfig, SetComTime, CloseCom create a particular condition to freeze CVI)?
Thank you and have a nice day.
Best Regards,
Stefano