Open Side Menu Go to the Top

08-18-2009 , 04:07 AM
Gimmick account ldo, but had a few questions about socket programming.

Basically I have some sort of machine that is controlled via a serial connection (does it matter if it's RS232 or RS485? pretty sure it's the latter). I need to write some cpp code that controls it. Basically how I assume this works is you just set the bits for what you want to do, and it does it.

Is this any different for either of the RS protocols? I'm hoping you just set the "COM1" or whatever to whichever port we're trying to use, and read/writing should be simple.

Sorry if this is mangled and vague, I'm learning it on the fly and would appreciate any tips you guys might have. I'm good on binary, hex and all of that, so I'm just mainly just worried with the protocol for actually reading and writing to and from the serial port. Hopefully it's not too complicated. Thanks!
Couple quick Qs about Socket Programming?
150% up to $2,000 Welcome Bonus on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Couple quick Qs about Socket Programming?
08-18-2009 , 08:11 AM
Actually, not so obvious why you need a gimmick account for this, but I think you'll get better answers from the software forum guys.
08-18-2009 , 08:29 AM
Quote:
Originally Posted by BHP
Gimmick account ldo, but had a few questions about socket programming.

Basically I have some sort of machine that is controlled via a serial connection (does it matter if it's RS232 or RS485? pretty sure it's the latter). I need to write some cpp code that controls it. Basically how I assume this works is you just set the bits for what you want to do, and it does it.

Is this any different for either of the RS protocols? I'm hoping you just set the "COM1" or whatever to whichever port we're trying to use, and read/writing should be simple.

Sorry if this is mangled and vague, I'm learning it on the fly and would appreciate any tips you guys might have. I'm good on binary, hex and all of that, so I'm just mainly just worried with the protocol for actually reading and writing to and from the serial port. Hopefully it's not too complicated. Thanks!
Not sure which OS your controlling machine will be running in, but if it's Windows or Linux then these should help:

http://www.codeproject.com/KB/system/serial.aspx

http://tldp.org/HOWTO/Serial-HOWTO.html

IIRC, it's not even that hard to work with the chips directly if you have to.

Juk
08-18-2009 , 05:45 PM
Pinouts out and sending signals down particular pins might matter - depends immensely what the device is. Have you tried googling for that kind of thing? Pinout diagrams etc.


Why would you create a gimmick account. Afraid that someone might discover you're actually smarter then you pretend to be, or not as smart as you talk yourself up?asdf lkjadf lkj
08-19-2009 , 01:32 PM
What is your target platform? Windows? Windows won't let you directly access the port unless you are writing virtual device driver in assembly language following strict Microsoft procedures.

Also there are many ready made (and free) socket mangling solutions coming with most development environments like Visual Cpp, Inprise Turbo Cpp, etc.

What exactly is the hardware you want to control/read? Does it have native drivers? Maybe you can search the internet and find the pin mapping if you really insist on low level access. Just a thought.
08-21-2009 , 03:22 AM
Quote:
Originally Posted by kerowo
Actually, not so obvious why you need a gimmick account for this, but I think you'll get better answers from the software forum guys.
thanks. gimmick in case i somehow get linked to this website.

Quote:
Originally Posted by jukofyork
Not sure which OS your controlling machine will be running in, but if it's Windows or Linux then these should help:

http://www.codeproject.com/KB/system/serial.aspx

http://tldp.org/HOWTO/Serial-HOWTO.html

IIRC, it's not even that hard to work with the chips directly if you have to.

Juk
thanks Juk, you've always been a big help. i was already using the code from the first link, and am making my way through the second link slowly.

Quote:
Originally Posted by nuclear500
Why would you create a gimmick account. Afraid that someone might discover you're actually smarter then you pretend to be, or not as smart as you talk yourself up?asdf lkjadf lkj
I ask a lot of stupid questions, so no, my 2p2 rep doesn't really matter to me.

Quote:
Originally Posted by Sheetah
What is your target platform? Windows? Windows won't let you directly access the port unless you are writing virtual device driver in assembly language following strict Microsoft procedures.

Also there are many ready made (and free) socket mangling solutions coming with most development environments like Visual Cpp, Inprise Turbo Cpp, etc.

What exactly is the hardware you want to control/read? Does it have native drivers? Maybe you can search the internet and find the pin mapping if you really insist on low level access. Just a thought.
So I've learned some more about the project since I first posted this, so here's an update:

It's a machine that comes with a dedicated computer. You connect to this computer via serial, which basically just waits for input via the buffer. So i'm assuming all I need to do is read from the buffer and write to the buffer. visual cpp on windows. I have the codes/switches of the controls I read/write so that's not really a problem.

A couple questions though:
I haven't tested the hardware yet, so if I cant find anything I'll just do trial and error.

1) To open the port, it says
Code:
serial.Open(_T("COM1"));
serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
serial.SetupHandshaking(CSerial::EHandshakeHardware);
What convention are port names in, and what do I replace COM1 with? I tried googling and came up empty.

2) As a convention, should I be sending the buffer binary or hex? It's expecting 32bit input I think. I'm assuming hex because binary would be tedious and unwieldy.

Hope these questions are really easy to answer, if it requires any research on your end don't bother. I'll keep googling or ask a dedicated coding forum. Thanks!
08-21-2009 , 07:46 AM
Quote:
Originally Posted by BHP
What convention are port names in, and what do I replace COM1 with? I tried googling and came up empty.
On old PC motherboards you usually had just "COM1" and "COM2" (one was usually a 9-pin serial port and the other a 25-pin port). In Linux they are named differently as: "/dev/ttyS0", "/dev/ttyS1", etc.

Quote:
2) As a convention, should I be sending the buffer binary or hex? It's expecting 32bit input I think. I'm assuming hex because binary would be tedious and unwieldy.
You'll have to look at the format of the command sequences to see how you should be constructing the data packets (the format could be binary flags or hex values or even ASCII strings).

When sending it you will just need to send it in "chunks" the size the C++ send function is expecting (ie: single bytes, 16 bit words, 32 bit words or whatever it uses). I think it will most likely just take single bytes (or at least have an overload for it).

Juk
08-21-2009 , 12:41 PM
thanks a lot everyone!
Couple quick Qs about Socket Programming?
150% up to $2,000 Welcome Bonus on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Couple quick Qs about Socket Programming?
Closed Thread Subscribe
...

      
m