954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Just a short answer.

Hi guys.Can you write a program that reads data through a com1 serial port that communicates with a plc using c++ and inline asm instead of the ladder logic interface?
I work at a cinema as a projectionist and the whole booth is automated with a bunch of these monsters through a CAN network.
The PLCs are programmed with a ladder logic interface with which i don't cope to well so before i begin studying the 8250 registers or the win32 functions for i/o i would like to know if i would be getting somewhere using this approach.Many thanks in advance!

caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 

The way to communicate through com1 will depend on the operating system. MS-Windows, use CreateFile() to open the com port, then ReadFile() and WriteFile() to read/write to it. See commuications functions for more details.

I don't know a thing about ladder logic because I never programmed a PLC.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Ok thanks sir.I am getting a handle to the com1 port , which i'm sure about because i'm using the FormatMessage() function and it says "Operation completed succesfully".I don't really know of a better way than polling but there's not a single byte comming from that port.

caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 

When you open the com port with CreateFile() you can specify a callback function that MS-Windows will call when data arrives at the port. That way you don't have to keep polling it to find out if there is data.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Like in LRESULT CALLBACK WndProc()? Isn't that an infinte loop?

caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 

So i will use something like CALLBACK WaitCommEvent()?

caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 
So i will use something like CALLBACK WaitCommEvent()?

Yes you can use that, but put it in another thread so that it doesn't block the main program.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: