Advertisement

COM and LPT port

Started by December 26, 2000 08:42 AM
13 comments, last by SKSlayer 23 years, 10 months ago
How can I read what enters the COM1, COM2 and LPT port ? I need the lowest level functions as it''s to make support for something I made myself (A little infrared receptor made from piece of junk) (I wanna make a command, like a tele one, but, to control the PC, so I need to be able to read through the port).. And I haven''t made the plug yet, so, I can''t guess whether I will make it COM1 COM2 or LPT1 ...
(you can find me on IRC : #opengl on undernet)
You''re not alone in your wanting to use COM ports, ect. What I''d love to do is have them setup like a switch... ie. I would like to control actual electric current through them. Not sure if thats feasable or not...
I think Assembler is best suited to this kinda low level stuff... I guess we better get learning, eh??
Protozone
Advertisement
I know there is way to do that in C, but dunno how
(you can find me on IRC : #opengl on undernet)
I could do that under MS-DOS and Linux but with Windows I''d have to do a little digging! Let me know what OS your using and I''ll see if I can get you that info.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Gimme the DOS stuff they will do fine
(I run under Win9x)
(you can find me on IRC : #opengl on undernet)
DJGPP is your best solution (DOS).
I don''t think you can do it under Windows, without writing it as a VXD

it has stuff like inportb, outportb, or you can use inline assembly.

This stuff gets nasty real fast! Good luck.

~~~
Cheers!
Brett Porter
PortaLib3D : A portable 3D game/demo libary for OpenGL
~~~Cheers!Brett PorterPortaLib3D : A portable 3D game/demo libary for OpenGLCommunity Service Announcement: Read How to ask questions the smart way before posting!
Advertisement
Brett Porter is correct in saying that useing the dos methods in win9x would require writeing your program as a vxd (device driver)! This is because Windows selfishly hoggs all the system resources to itself!
I will however look up the dos info so you can play with it a bit!?!? And I do have an idea of where I might be able to find info on win9x I/O port programing but I''ll have to check some refferences first!

l8r,
Rob
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Grrr, windows pisses me off real hard ...

So, tell me after you dug a bit
(you can find me on IRC : #opengl on undernet)
Guys,

Under Win32 the proper way to read from the COM port is with the File I/O APIs ( CreateFile, ReadFile, WriteFile, CloseFile ). The follow is a snippet from the the Win32 SDK.

Monitoring Communications Events
The following example code opens the serial port for overlapped I/O, creates an event mask to monitor CTS and DSR signals, and then waits for an event to occur. The WaitCommEvent function should be executed as an overlapped operation so the other threads of the process cannot perform I/O operations during the wait.

HANDLE hCom;
OVERLAPPED o;
BOOL fSuccess;
DWORD dwEvtMask;

hCom = CreateFile( "COM1",
GENERIC_READ | GENERIC_WRITE,
0, // exclusive access
NULL, // no security attributes
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL
);

if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
}

// Set the event mask.

fSuccess = SetCommMask(hCom, EV_CTS | EV_DSR);

if (!fSuccess)
{
// Handle the error.
}

// Create an event object for use in WaitCommEvent.

o.hEvent = CreateEvent(
NULL, // no security attributes
FALSE, // auto reset event
FALSE, // not signaled
NULL // no name
);

assert(o.hEvent);

if (WaitCommEvent(hCom, &dwEvtMask, &o))
{
if (dwEvtMask & EV_DSR)
{
// To do.
}

if (dwEvtMask & EV_CTS)
{
// To do.
}
}




---
Visit Particle Stream Studios - Home of Europa, Tachyon and winSkin
---Visit InterfaceFX - Home of Europa, Tachyon and winSkin
Thanks! I knew I had seen something on it but couldn''t remember what book it was in so I couldn''t find it. Your little snippet of code reminded me and now I found the refference I was looking for. A little late but I found it! I knew there was something about the standard i/o streams though.
l8r,
Rob
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]

This topic is closed to new replies.

Advertisement