Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

GetCommID for CWSerial Control

I'm using CWserial class in VC++. In Microsoft MSCOMM control exists the GetCommId property for retrieve the handle of object.
How can I retrieve handle of CWserial objcet in VC++
I didn't found any help in documentation of MEasurement Studio
0 Kudos
Message 1 of 6
(5,308 Views)
Hi,

you can try and look at the example code that is found at the following link. It shows how to configure, read and write to a Serial port using the CWSerial Class in Visual C++ 6.0.

http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3E7AF56A4E034080020E74861&p_node=DZ52121&p_source=External

Best Regards,

AlessioD
National Instruments
0 Kudos
Message 2 of 6
(5,308 Views)
credo che l'italiano sia la nostra lingua comune dunque scrivo il commento al tuo suggerimento. avevo gia' scaricato il file da te consigliato. il pb e' che la classe seriale NI non ha in se un metodo tipo GetCommId presente in MScomm credo questo per una scelta progettuale. dall'help di microsoft vedo che GetCommId del controllo MS ricava l'handle del file associato alla risorsa seriale, ovvero quello che si ottiene con la funzione CreateFile. purtroppo la ma conoscenza di programmazione windows non e' molto approfondita e dunque chiedevo come mai NI non ha deciso di includere un metodo simile a GetComId oppure un'altra funzione della classe che restituisse l'handle in questione

grazie e saluti
0 Kudos
Message 3 of 6
(5,308 Views)

The vcserial.zip file at the given address was very useful. I was able to configure the serial device and also i was able to write the command in text(edit) box and subsequently  i was able to read the data using the read command button.

But i want to modify the program so that inspite of taking the command from text box it should take from variable or directly . Also we are not able to understand the variable defined vText of COleVariant datatype. I have sent the code how we want to implement.

The statements to write to serial port is as follows: 

//Clicking the Write Button causes the Send String to be written to the device

            COleVariant vText;

 

            UpdateData(TRUE);

            vText= m_writeText;

            m_cwSerial.Write(vText);

 

we are writing "#02M\13"  command in the text box and send the data to serial port by pressing write command button and subsequently pressing read command button to get back the response. It is working fine.

 What we want:

Inspite of taking data from edit box the command  "#02M\13" it should be directly write the command "#02M\13"  by storing  in the variable or by any other means.

What we tried:

 //Clicking the Write Button causes the Send String to be written to the device

            COleVariant vText;

 

            COleVariant temp;

 

            // UpdateData(TRUE);

//vText=m_writeText;

 

 temp = "#02M\13";

m_cwSerial.Write(temp);

 

 

 

 

it writes to the device but read command gives.

 

 

0 Kudos
Message 4 of 6
(4,916 Views)
Hi RBCHAVAN,
 
The problem might be caused because of the way strings are interpreted using escape characters. A backslash character in a lot of programming languages signifies an escape character.
 
You might want to try:

temp = "#02M\\13";    //Note the double backslashes.

Does that work?
Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 5 of 6
(4,909 Views)

Thanks for the suggetion. The program is working fine

 

0 Kudos
Message 6 of 6
(4,878 Views)