Solved

Serial port Comms

Posted on 1999-01-02
5
178 Views
Last Modified: 2010-04-16
How do I get COM 1 to Tx/Rx 8 bits?
WinProcs only do 7Bits since the buffer is PChar
ok so Ord(Chr(255))=255 but WriteCom from one PC and ReadCom on another 255 comes out as 127
even with BulidComDCB with mode COM1:9600,n,8,1,p

Ta Pete
0
Comment
Question by:PeteTheHat
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216799
I found this in SWAG...maybe it will help you.

---BEGIN PASTE---

>What I need to do is write an arbitrary number of bytes to a serial
>port.  Period.  No modem commands, no acknowledgement from the
>distant end of the serial line, no reading of the port (at least, not
>yet), no nothing except FOR i := 1 TO X DO Send(AByte);

Well, that's an easy task in D2.  Here is how you open the port:

  Var Port:STRING;  Handle:INTEGER;

  Port:='COM2';  // or whatever COM port
  Handle:=CreateFile(PChar(Port),GENERIC_READ+GENERIC_WRITE,
                               0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
  If Handle=INVALID_HANDLE_VALUE then exit; // handle the error if it didn't open

  SetupComm(8192,8192);  // works best if you set the buffer size high

Now you write the characters to the port using one of two ways...

Using WriteFile:

  Var DataToSend:STRING;  Written:DWORD;

   WriteFile(Handle,DataToSend[1],Length(String),Written,Nil);

The above will use the buffer to send the data, so it will return before
the actual data has been sent to the port, so be sure to delay a bit
before closing the port so you don't truncate the outgoing data.  The
parameters are Modem handle, Where the data is, The number of
bytes to send, Returns the number of bytes actually sent, and the last
parameter is if you want to do overlapped writes (sounds to me like
you don't need to in your situation).

The other way to send data to the port is

  Var K:CHAR;
  While not TransmitCommChar(Handle,K) do Application.ProcessMessages;

This sends one character at a time.  TransmitCommChar will return
FALSE if the last character sent hasn't actually gone out the port yet,
so you have to loop like above to send every character. It also returns
FALSE if the port hasn't been opened properly, so make sure it was
opened before you get stuck in a loop somewhere./

When you are done with the port, use

   CloseHandle(Handle);

To close the port and turn off the modem.   Make sure you do this
in your error handlers because if the application terminates without
doing this you'll have to reboot your system to get access to the
COM port a second time.

I hope this is what you were looking for.

----END PASTE---
0
 

Author Comment

by:PeteTheHat
ID: 1216800
Cheeers Scrapdog ill give it a whirl soon ive been down for a while back soon again ta
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1216801
You there?
0
 

Author Comment

by:PeteTheHat
ID: 1216802
Ill buy that for a dollar ta Scrapdog give me an answer u got the points
0
 
LVL 5

Accepted Solution

by:
scrapdog earned 100 total points
ID: 1216803
Thanks for the points!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help with If Then Statement 8 322
using a list of objects, Delphi 3 594
Neural Networks with Delphi 3 1,488
Kind of encoding 3 417
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now