LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sending commands and reading data - RS232

Hello guys !

 

I have a special problem communicatin through RS232 with a PIC microcontroller.

 

The problem :

 

On push of a button i want to read a value from the microcontroller.

On another push of a button, i want to write a value to the microcontroller.

 

However, i get an error : "VISA:  (Hex 0xBFFF0015) Timeout expired before operation completed."

 

I've tried to search the forum for similar problem, but i haven't found a suitable answer.

 

I also post my current code for reference. I'm using LabView 8.5.1.

 

The RS232 communication is working fine (i can read and write from the PIC).

I tested the connection extensively so i think that te problem is not there.

 

 

Can u help me ?

 

Thank you !

0 Kudos
Message 1 of 7
(6,430 Views)

Hi Andoro,

  As you said that you can read and write from the PIC,now coming to the LabVIEW program,just add some delay between write and read operations and actually debug the PIC program whether it is reading values and writing values.

 

Thanks and regards,

srikrishnaNF

Regards,
Srikrishna


Message 2 of 7
(6,420 Views)

Thank you 4 your answer !

 

I tried the proposed sollution in the form of the attached vi but the error remains.

 

Is there a way to use event structures to accomplish this task ?

 

Thank you!

0 Kudos
Message 3 of 7
(6,417 Views)

Hi Andoro,

  Yes,you can use event structures with two buttons,one for read and one for write..Before that have you fixed the same serial port configuration properly like same baud rate,control hardware for both PC and PIC;Please have a look at the figure below...+_BD.png

Regards,
Srikrishna


0 Kudos
Message 4 of 7
(6,409 Views)

Hello !

 

Thank you 4 your answer !

 

The proposed sollution also doesn't work.

 

I don't really know what else to try Smiley Sad

0 Kudos
Message 5 of 7
(6,402 Views)

Are you waiting for a response from the device after you send it a command? Are you getting any data back? A simple delay is not a very good solution since your program may work for one given situation but the hard delay may not in others. You can use a VISA event to wait for data at the serial port. How much data are you expecting? If it is a larg eamount of data you may want to calculate the timeout for the read based on the amount of data and your given BAUD rate. If you expect a large amount of data you may not have your timeout set long enough for all the data to arrive, especially if you are using slower BAUD rates.

 

I noticed in your code that you have enabled the read to look for a termination character. Does your device send one? If not, you may be getting the error because you have not received the 1000 bytes you indicating you want to receive. If you will not be getting a termination character and you don't know how much data you will be receiving you need to create some type of algorithm to read data and decide when to stop. Th eapproach I use is to read a single byte. This read will contain the maximum timeout to wait for the data to arrive. Once a single byte has been read I continue reading chunks of data using a small timeout value. This value should be long enough to allow any small delay that occurs in the data as it is being sent from the device but short enough to indicate the data is complete once a timeout does occur. This timeout error is discarded since it is not a true communication error.

 

NOTE: You should avoid using controls as variables. You have your Byte to Read controls set as default values and hidden. Therefore they are nothing more then a constant. Hiding controls simple to hide "variables" is not a good coding practice. Either expose the controls to teh user or use a constant.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 6 of 7
(6,374 Views)

Mark has already discussed lot many things

I suspect that you are getting time out error just beacase data sent by PIC is not 1000 bytes.

 

For testing you can use "VISA bytes at serial port" vi to actually check how may bytes have already arrived at port and then read those many bytes on port

We can help you better if you can discuss bit more about the packet format

Tushar Jambhekar
tushar@jambhekar.com

Jambhekar Automation Solutions
LabVIEW Consultancy, LabVIEW Training
Rent a LabVIEW Developer, My Blog

0 Kudos
Message 7 of 7
(6,360 Views)