ni.com is currently experiencing unexpected issues.
Some services may be unavailable at this time.
03-09-2006 10:52 AM
A Text box is been used to display the activity on a serial port.
How can I interact with the serial port via this text box?
I am inputting from a string and on pressing the enter key what ever is in it is been output to the serial device and I can see the response in the test box
Also the problem with this is the Esc key is not recognised!!
How can I over come this?
Thanks
Simon
03-09-2006 03:01 PM
Hi Simon,
I dont know if i hv understood ur question correctly but let me take a shot at it.
So basically you are typing a string in this text box and then when u hit enter you want the string to be sent via serial right?
I dont know if you have looked at the samples...go to the directory National Instruments\CVI70\samples\rs232 on ur computer....see hw the transmit routine wrks.
have a command button with callback to SendAscii.....so when u press this button it write to the serial port. Also you can select the termination byte u want...in the code below it uses LF or CF....
SendAscii (void)
{
GetCtrlVal (panel_handle, SERIAL_TBOX_SEND, send_data);
GetCtrlIndex (panel_handle, SERIAL_SENDTERM, &send_term_index);
switch (send_term_index)
{
case 1:
strcat(send_data, "\r");
break;
case 2:
strcat(send_data, "\n");
break;
}
stringsize = StringLength (send_data);
bytes_sent = ComWrt (comport, send_data, stringsize);
}
03-10-2006 02:36 AM
Hi,
Thanks for the pointers but these only go some of the way to what I am trying to do.
I am trying to get away from the need for a button to sent data and if possible remove the need for a carriage return!!
The device at the end of the serial port will respond once it receives valid data i.e. A, sX, 4, sy are all examples of valid data, no carriage return required.
In the attached word document will give code I have used so maybe some one can point me in the right direction.
Thanks
Simon
03-10-2006 04:01 AM
Simon, I looked at your code but there are several things not so clear, the main one being that you installed a callback on the serial port but you have not given us its code.
Anyway, I have added some comments to your code and I am attaching it to this message: they may help you in developing your application.
03-10-2006 06:58 AM
Roberto,
This is the full code, some is also unclear to me but if it is in it works and if it is removed it stops working so what it is actually doing has still to be nailed down.
This is a Frankenstein of a program, bits from a number of places!!
As I said before I have used code from other places and adjusted till it worked in a way I feel is OK for me.
If there are bit left over in time they will get removed
The over all aim to have a hyper terminal with in the control of CVI.
Thanks for the help
Simon
03-10-2006 11:00 AM
Srm27 wrote:
The over all aim to have a hyper terminal with in the control of CVI.
03-10-2006 01:26 PM
Simon, i totally agree with Roberto....i think you code is all over the place.....have a look at the sample program and wrk you way from there.
Good luck
k1_ke
03-13-2006 05:53 AM
Hi,
Thanks for the input.
True the code is all over the place but that is what comes of stringing code together till it works in the way I expect it to work (trial and error and no formal coding education!!!)
If I use the example one short fall is I am unable to get the serial device to recognise the “Esc” key.
How do I go about getting the application to recognise the “Esc” key and sent the required code to the serial device?
Thanks
Simon
03-13-2006 07:08 AM
So you must:
- read the Esc key from the keyboard
- embed it in the string to send to the device
right?
In this case you can install a callback on the input string in which to manage the EVENT_KEYPRESS event this way:
switch (event) {
case EVENT_KEYPRESS:
virtualKey = eventData1 & VAL_VKEY_MASK;
asciiCode = eventData1 & VAL_ASCII_KEY_MASK;
if (virtualKey != 0) {
switch (virtualKey) {
case VAL_ESC_VKEY:
GetCtrlVal (panel, control, msg);
// This is necessary if you use a textbox since sometimes a carriage return is added when pressing the Esc key
if (msg[strlen(msg) - 1] == 10) msg[strlen(msg) - 1] = 0;
strcat (msg, "\33"); // Add the Esc key
// In case you use a simple string you can SetCtrlVal instead
ResetTextBox (panel, control, msg);
// This is necessary on the textbox since the cursor is now at string start
SetCtrlAttribute (panel, control, ATTR_TEXT_SELECTION_START, strlen (msg));
break;
}
}
}
03-13-2006 10:29 AM
Roberto,
Thanks for that as I now have something that works a lot smother.
As always there is another question!!!!!
Where did the following two lines come from?
virtualKey = eventData1 & VAL_VKEY_MASK;
asciiCode = eventData1 & VAL_ASCII_KEY_MASK;
Can, if at all, this be used in conjunction with “case EVENT_KEYPRESS:” for the input from any test box receiving a single letter/number, such as setup the com port to be used in an application?.
I have been trying but failing (nothing new about that!!!!!!)
Thanks
Simon