Serial communication with Siemens CP340 and LabVIEW

Hehe, it explains great! I will try that tomorrow, but all of this in the VISA read loop? Should i not use a local variable and do this in a separate while loop?

EDIT: I have the VISA read and write in the same while-loop.. will this affect the results?
 
Play around with the shift registers a bit. they are very handy for things like this. Remember you need to define the shift register by giving it something to start with on the left hand side (i.e. the enpty string constant). the great thing about the shift registers is they do not take up as much memory as local variables and it keeps it all contained until you end you loop, and at that point it passes the full contents of the register out. at that point you can put it in a local variable if you want. as soon as the loop ends and it passes out the information, the shift register de-activates and starts over again the next time you run your visa read loop.
 
EDIT: I have the VISA read and write in the same while-loop.. will this affect the results?

I never actually tried reading and writing in the same loop. I am not sure what it would do to the buffer. It may just be cleaner programming to seperate it out. anything the piles up on the serial port while you are not running the read loop will stay there until you get back to it as long as you do not clear it. so for example, you should be breaking your read loop every time you get your full string in order to pass the result out. you can then do your write loop, then go back to your read loop. if anything came in on the serial port while you were writing, it should still be there in the the buffer waiting to be read.
 
Ok, i have now got quite a bit of communication working.. I placed a shift register in the while loop around both the serial read and write block. (if i placed them in seperate while loops, none of them worked).

Replace array subset works fine, and replaces the value in the array according to the value of "bytes at port". There is still some "flickering" in the values, but with some filtering i think i will be able to use these values further on in the project!

Another thing though.. I thing the com is extremely slow.. Now i transfer 12 ascii chars (12x8bits= 96 bits) about three times a second, wich equals 96x3=288 bits/s ?? I can`t imagine that the siemens PLC CP340 module is the bottleneck. I can of course incease the number of chars, but still an update rate of 3Hz is quite slow.
 
You should not be getting any "flickering" in the values. Something is still not quite right if you are seeing it. If your data string from the PLC is a consistant length and format, you should be able to read it in a stable way.

Good job so far though. I remember I spent days banging my head against the wall when I was first trying to get this figured out too. The shift register on the while loop is a very useful tool, you will probably find yourself using it all the time :)

As far as your pooling speed goes, is the PLC sending you data in response to LabView sending it a command or is it unsolicited?

Is there a lot of time between string transmissions or are the strings transmitting slow? The VISA default is 9600 Baud.
 
Apoligize the late reply. I seem to finally have completed the communication.! Thank you very much for the assistance! Now I of course have some new compications with the TCP/IP com, so I have started a new thread.
 

Similar Topics

Hello everyone, I want to make a serial communication using Siemens S7-1200 with CM 1241 (RS-232) and communicate with my Arduino. Here is the...
Replies
13
Views
9,812
Currently,we are facing the communication go through with 422 tx+ and tx-. Mitsubishi fx5u series is used and using command rs2. But the package...
Replies
0
Views
104
I have wasted a week trying to figure out how to connect an SLC5/03 with my laptop. I do not have and can not Buy the 1747 UIC and PC3 cables. I...
Replies
14
Views
2,557
MELSEC A RS422 (25pin) <> iQR C24 Serial RS232 (9pin) - Simple PLC Communication Communication from a MELSEC-A Series CPU (RS-422 – DB 25 Pin)...
Replies
4
Views
1,044
Hey guys, I have a problem reading weighing data from AND AD4406 with OP-05 RS-232C Relay and Control input using Rockwell PLC Micro820. I already...
Replies
0
Views
945
Back
Top Bottom