Solved

status_invalid_parameter noticed when sending a message to a serial port

Posted on 2006-10-20
14
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17783254
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
ID: 17789722
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
ID: 17790808
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:abcast
ID: 17790833
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
ID: 17791853
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
ID: 17791871
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
ID: 17792109
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
 

Author Comment

by:abcast
ID: 17792147
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
ID: 17792173
well that's a nasty device ... what is it for ?
0
 

Author Comment

by:abcast
ID: 17796221
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
ID: 17803265
I'll have to see the transmitcommchar function in the sdk ... hope to  find an explanation...
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17803323
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
ID: 17850901
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
ID: 17851905
your welcome :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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