ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Textbox

Hi,
 

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

0 Kudos
Message 1 of 12
(4,855 Views)

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);
}

Hope it helps. I will get back to with ur que abt the Esc key
 
k1_ke
0 Kudos
Message 2 of 12
(4,840 Views)

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

0 Kudos
Message 3 of 12
(4,831 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 12
(4,819 Views)

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

0 Kudos
Message 5 of 12
(4,808 Views)


Srm27 wrote:
The over all aim to have a hyper terminal with in the control of CVI.



Simon, given this target, my suggestion is you take a look at serial.prj example (you'll find it in <cvidir>\samples\rs232 folder): basically you only need to customize it installing the receiving com callback after you open the port so that you can receive messages without the use of the "read" button.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 12
(4,789 Views)

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

0 Kudos
Message 7 of 12
(4,781 Views)

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

0 Kudos
Message 8 of 12
(4,745 Views)

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;
     }
   }
 }



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 12
(4,736 Views)

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

0 Kudos
Message 10 of 12
(4,719 Views)