Hello all,
I have an embedded PC with 8 serial ports. (COM1 through COM8). The application running on this PC defaults to COM1 and you cannot change that. I need to look at data on the other ports. In other words, I need to tell the embedded PC that COM 4 is COM1. I have been doing this with a VB program that I wrote calling batch files using a Change Port command for example if I want to look at the data on COM 5 the VB program runs a batch file containing a [chgport COM1=COM5]. When I need to look at data on COM1 the VB program runs a batch file with [chgport /D COM1].
The above is not working very well. It does work but is not reliable. Is there a method within C# to redirect the serial ports? Again, the application running on the embedded PC (OS is XPE) will only look at COM1 so I have to redirect the data from another port to COM1.
Thank you in advance for your time and help.
Loading

AlanRank #669 · 3.6K reputationPosted Oct 18, 2008, 2:02 PM EDT
To my knowledge, there's nothing in the SerialPort class or elsewhere in the compact framework that would enable you to remap the COM ports.
Rather than use a batch file, have you tried to call chgport directly using the System.Diagnostics.Process class? The following worked OK when I tried it just now:
using System;
using System.Diagnostics;
class Test
{
static void Main()
{
string fileName = @"c:\windows\system32\dllcache\chgport.exe";
string args = "/C " + fileName + " /QUERY";
Process.Start("cmd.exe", args);
}
}
kyle43 reputationPosted Oct 18, 2008, 6:50 PM EDT
I will give this a try. Thank you for your help.
kyle43 reputationPosted Oct 19, 2008, 3:22 PM EDT
I was unable to view the port query when I ran the code that you posted. Any suggestions?
AlanRank #669 · 3.6K reputationPosted Oct 19, 2008, 3:35 PM EDT
You should be able to view the output by redirecting it to a file (ports.txt, say). Just change the 'args' line to this:
string args = "/C " + fileName + " /QUERY >ports.txt";