Solved

status_invalid_parameter noticed when sending a message to a serial port

Posted on 2006-10-20
14
327 Views
Last Modified: 2012-06-21
I have an application that runs fine for quite a while.  At some point, this app which communicates using the serial port, begins to have issues.  Using a serial port sniffer, I noticed that when an 0x06 is sent out by my app (ACK), an "status_invalid_parameter" is displayed alongside the ACK in the sniffer's logs.  What might be causing this?
0
Comment
Question by:abcast
  • 8
  • 6
14 Comments
 
LVL 7

Expert Comment

by:Mohamed Zedan
Comment Utility
What device are you communicating with  ..
and how are you using the serial port... component,,, or custom built class?

what is the scenario of data between the application and the device when the error happens ?
0
 

Author Comment

by:abcast
Comment Utility
The device is a 3rd-party device (not running Windows).  It's just a piece of hardware.  The client is running Windows2k, and was developed using C#.  I'm using the Windows API when I send a byte immediately, such as an ACK.  

When the error happens, it appears that the ACKs might not be getting through.  The device then repeats its responses for some time, since it probably never received an ACK.  
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
Comment Utility
I have dealt with access control devices , mobile phone, pbx machines... and alot more serial devices .. could you post how you are sending the ACK to the device ... Also I have used the comm control ,, windows api and the wounderfull sax communications component which was included for free in the vb.net resource kit... which is the easiest of all to use so please post the code you are using to send the ACK ...
0
 

Author Comment

by:abcast
Comment Utility
SerialPort class:
            /// <summary>
            /// Sends a byte immediately ahead of any queued bytes.
            /// </summary>
            /// <param name="tosend">Byte to send</param>
            /// <returns>False if an immediate byte is already scheduled and not yet sent</returns>
            protected void SendImmediate(byte tosend)
            {
                  CheckOnline();
                  if (!Win32Serial.TransmitCommChar(hPort, tosend))
                  {
                        ThrowException("Send immediate failure");
                  }
                  GC.KeepAlive(this);
            }



Win32Serial class:
            [DllImport("kernel32.dll")]
            internal static extern Boolean TransmitCommChar(IntPtr hFile, Byte cChar);
0
 
LVL 7

Accepted Solution

by:
Mohamed Zedan earned 500 total points
Comment Utility
where do you set the port settings like com1 ,,, baudrate , databits, stopbit,parity ....

why don't you use WriteFile to send the char to the serial port ...
also have a look at this class

http://www.codeproject.com/dotnet/DotNetComPorts.asp
0
 

Author Comment

by:abcast
Comment Utility
I do the settings in another area of the code, but that isn't causing a problem.

Why should I be using WriteFile?  What is the benefit of that vs TransmitCommChar?

I looked at the link quickly.  We may have problems using 3rd-party software like the one in the link.  Also, using that would require an extensive rewrite of my code, and I'd rather not do that.
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
Comment Utility
The link I provided isn't a 3rd party component it's an open source component...
as for writefile
writefile  allows to send a whole line of characters as well as single characters... it also allows for asynchronous writting to the serial port...

while transmitcommchar sends only one char and is synchronous...

and other than that I allways used writefile for all my work :))
please try that and tell me the result....
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:abcast
Comment Utility
I only use TransmitCommChar to send that one byte.  I have switched to using writefile for sending the ACK byte.  I will run the app overnight and see what happens.

The reason I have been using TransmitCommChar is due to the fact that the device on the other end needs to receive the ACK within 1000 ms of sending its data.  If it doesn't receive it w/in 1000 ms, it re-transmits.  I wanted to make sure that the ACK got there in time, and I was under the impression that TransmitCommChar was the best way to do this.  
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
Comment Utility
well that's a nasty device ... what is it for ?
0
 

Author Comment

by:abcast
Comment Utility
The device is pretty new, but the protocol is decades old.  The device is a video routing switcher.  I have tested using writefile against a simulator.  All I know is that is hasn't caused additional problems, since we are not able to reproduce this problem against a simulator.  I plan on connecting to the actual device tomorrow.  I will keep you posted.  Hopefully, I can put this issue to rest.

Any ideas as to why the TransmitCommChar call was resulting in this error after some time?
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
Comment Utility
I'll have to see the transmitcommchar function in the sdk ... hope to  find an explanation...
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
Comment Utility
that is what is said about the function in the SDK :

TransmitCommChar

The TransmitCommChar function transmits a specified character ahead of any pending data in the output buffer of the specified communications device.


BOOL TransmitCommChar(
  HANDLE hFile,
  char cChar
);

Parameters
hFile
[in] Handle to the communications device. The CreateFile function returns this handle.
cChar
[in] Character to be transmitted.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The TransmitCommChar function is useful for sending an interrupt character (such as a CTRL+C) to a host system.

If the device is not transmitting, TransmitCommChar cannot be called repeatedly. Once TransmitCommChar places a character in the output buffer, the character must be transmitted before the function can be called again. If the previous character has not yet been sent, TransmitCommChar returns an error.

I think the last part in the remarks is what is causing you the trouble.... but your sendimmediate function handles that case and throws an exception !??! well ... keep me posted to your progress :)
0
 

Author Comment

by:abcast
Comment Utility
Looks like that did it.  The problem usually happens about 16 hours after the client is started.  It went 4+ days, and no problem reported yet.  Thanks!
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
Comment Utility
your welcome :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

10 Experts available now in Live!

Get 1:1 Help Now