A simple program to send stuff over the COM port...

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(didn't know into which forum this question would be best suited, so here it is)
Hi, I've tried making my own COMport subrutine (on the PC), but I've had little succes (it works, but very unstable). So I was wondering if there is any simple program, console preferably for win, that, when invoked sends the contents of a specified file and then ends. Something I could simply invoke like:

comport_sender file_to_be_sent.txt COM1 9600,N,1,8

etc.

And it cant be a terminal where you have to actually do something, just invoke it.
Do you know of anything like that?

Thank you,

David Gustafik

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One of the problems, if using Windows XP, is that, when Windows goes off into space doing it's own background stuff, everything else has to wait until it completes. The result is that, occasionally, a character might get missed coming into the PC.

Is this the instability you are refering to?

If so, you will have to get a driver (MS_COM) or, some such thing. Even with commercial terminal programs, such as HyperTerminal, the Windows background activity can be quite troublesome.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm...I've actually given up making my own code (I'm not risking a heart attack).
Yes that's the instability, well, actually it's more that some chars I send FROM the PC get lost...

I was thinking something like the most simple console program that you simply invoke. I know under linux you can reroute the output of the console to a com port, you can do anything virtually. But windows with all its HANDLEs and WCOMs and.....ARGHH!

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you should try enabling parity on the data lines and increasing the data rate from 9600

stop it napoleon, i think you're bruising my neck meat!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

daqq wrote:
Hmm...I've actually given up making my own code (I'm not risking a heart attack).
Yes that's the instability, well, actually it's more that some chars I send FROM the PC get lost...

I was thinking something like the most simple console program that you simply invoke. I know under linux you can reroute the output of the console to a com port, you can do anything virtually. But windows with all its HANDLEs and WCOMs and.....ARGHH!

I have successfully used HyperTerminal at 115.2K BAUD to communicate with my projects.

The PC to target direction are typically keyboard command strings of about 10 characters, or so. I haven't noticed any problems with data loss in that direction.

But, from the target to PC direction, while the character strings are still only about 10 characters in length but, they are repedative and, I do get short-changed a character periodically. It always seems to be when Windows tries to go to sleep, I.E. Hibrenate. But, it doesn't seem to matter what BAUD rate I run with, the problem still seems to persist, though, less frequently at lower BAUD rates.

I use a lot of cursor positioning ESC commands to place data at specific locations in HyperTerminal. The data occasionally gets shifted to the left by one character just after Windows returns from its non-sensicle busy work. I wish I knew how to shut off the background tasking in XP.

My work-around was to add a means to refresh the HyperTerminal screen when this happens. While not the perfect fix, it is tollerable.

I am thinking that Windows XP still allows re-direction of file output to selected hardware and, vise-versa. I haven't had the need so, I haven't investagated that possibility with XP.

I have been thinking about taking one of my machines (or building up another machine) and switching it over to Linux. This would not be a bad thing as, my Table-Top mill has what is said to be an excellent machine control program that is Linux based - and, its all free!

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

Last Edited: Sun. Jan 14, 2007 - 05:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

not sure if it is directly related, but there is quite a bit of port interfacing info at www.beyondlogic.org

"You live and learn. At any rate, you live."

Douglas Adams

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have used these routines

http://members.inode.at/anton.ze...

with success (Send and receive) (using Visual-C).
But I did not do much with ist.
So there might be even better libraries.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey, daqq! You could at least tell us what language(s) you are using to build programs on the PC.

If you are using C++, and maybe specifically MSVC, then just open COMx as a file. Read from it, write to it etc... I'm sure there are others here that can give you advice if you are more of a VB, C# or guy.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm with microcarl on this one, investigate file redirection from the command line (or try PowerShell). I know that you could send a file (or echo text) out the COM port (with no flow control) simply with DOS redirection in the old days... something like:

echo >COM1: "Testing"

But I forget the exact format and how to configure the port parameters, that might be as simple as a MODE command (mode COM1: etc.).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dinofizz wrote:
not sure if it is directly related, but there is quite a bit of port interfacing info at www.beyondlogic.org

But its all DOS related. That is where I got my information to do the things I have done with the PC COM. ports.

How I learned to manipulate and control HyperTerminal? I did a lot of internet searching and a lot of trial & error!

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I really don't recommend any external DLLs or libraries for that, unless the library has free licence, has source code available and uses the native win32 calls.

There is a good example how to use com ports in windows with just regular win32 calls in wxwidgets (actually wxctb (wx-ctb/wx_ctb) contrib library).

I learnt the thing from there that whenever the com port is written, the flush command must be sent to start the transmitting immediately without further buffering.

Then I made a C++ object out of the routines, so using the com port is really a breeze. The receiving side must be polled though, unless you want to use some fancy-pants timer or thread for polling.

With my library, I can control and read every handshake line too, so implementing custom bit-bang protocols like I2C over serial port handshake lines is possible. Actually I made an I2C object too which uses the serial port object :)

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Hey, daqq! You could at least tell us what language(s) you are using to build programs on the PC.

Hmm...as the main IDE i'm using DEVC++ (latest nonbeta).

The problem with using hyperterminal and such is that you cant simply make a bat file and tell it

hyperterminal send_this_file file.x com1 9600 ... and_then_end_your_self

hmm...I'll be experimentig with some fine code that bobgardner sent me, but it's compiled under visual studio and devc++ isnt too happy and is reporting a gazilion errors.

Well, trial and error, here I come again...

BTW: Thanks everybody for your input.

David

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I know nothing at all about Dev C++ but I found a (the?) forum dealing with it in less than sixty seconds. It took me less than sixty additional seconds to do search there and get loads of hits, and without being able to actually assess the applicabiliy of any threads to your problem I would be surprized if there was nothing there that would point you in a useful direction.

You did search the Dev C++ forum, yes?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do this type of thing all the time with VB6. Before that I did it with QuickBASIC and before that with MBasic. I have attached a zip file with the project, form file and a sample transmit file.

If you use the Comm Event you can do sustained transmits and receives at high baud rates without losing characters.

Jeff

Attachment(s): 

Jeff Dombach, JLD Systems
"We do the stuff behind the buttons!"
Your source for embedded solutions with a 100% Guarantee.
http://www.jldsystems.com
Phone 717.892.1100

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

daqq wrote:

Hmm...as the main IDE i'm using DEVC++ (latest nonbeta).

I also use Dev-C++ for all my PC and AVR code editing. I've also been thinking about compiling AVR code on Dev-C++ in such way that all the relevant hardware (Timers and serial ports at least) is simulated to use whatever it is necessary so that the same C source code could compile to either PC target or AVR target.

The wxwidgets contribute library (wxctb) does compile on Dev-C++.

- Jani