我正在使用内部软件工具,该工具显示&日志格式化的诊断数据,这些数据是从我开发嵌入式软件的产品的串行调试端口收集而来的。它是C语言,非常古老。它使用Borland Turbo-C v1.01(版权1990!)构建。如果可能的话,我宁愿修改而不是重写现代环境的工具。如何在DOS/C中访问非标准COM端口(USB-> Serial,COM5 +)?
我想一次收集来自多个设备的调试数据。我曾设想过几个设备通过USB->串行适配器连接到集线器,并连接到PC(运行Windows XP)。运行每个设备的诊断工具的一个实例(再次,在Windows中),指向适当的COM端口。很简单,对吧?
不完全。观察串口初始化函数我的工作:
void serinit(int baudrate, char paristat, char adaptnum) {
int hibcon, lobcon, paricon;
if(adaptnum == '3') {
sioreg = lowbaud = 0x3E8; // SIO (Serial I/O Reg.)
intenreg = highbaud = 0x3E9; // IER (Interrupt Enable Reg.)
intidreg = 0x3EA; // IIR (Interrupt Ident. Reg.)
linecon = 0x3EB; // LCR (Line Control Reg.)
modemcon = 0x3EC; // MCR (Modem Control Reg.)
linestat = 0x3ED; // LSR (Line Status Reg.)
modemstat = 0x3EE; // MSR (Modem Status Reg.)
sintvect = 0x0C;
sintmask = 0x10;
} else if(adaptnum == '2') {
//omitted for brevity, similar to above w/ different magic numbers
} else {
//ditto
}
outportb(linecon, 0x80); // LCR - set up to set baud rate
switch(baudrate) {
case 9600: hibcon = 0x00; lobcon = 0x0C; break;
//more magic numbers for other baud rates
}
outportb(lowbaud, lobcon); // Baud Rate Divisor LSB
outportb(highbaud, hibcon); // Baud Rate Divisor MSB
switch(paristat) {
case 'o': //odd parity, 2 stop, 7 data
case 'O': paricon = 0x0E; break;
//more magic numbers for other parity settings
}
outportb(linecon, paricon); //Line Control Register
outportb(intenreg, 0x01); //IER - receive enabled
outportb(modemcon, 0x09); //x x x x +out2 x -rts +dtr
imodemcon = 0x09; //update image
inportb(sioreg); //Just in case there's anything lurking in the register
intvsave = getvect(sintvect);
setvect(sintvect, serint); //Set up interrupt vector.
outportb(0x21, inportb(0x21) & !sintmask); //OCW 1 - enable serial interrupts
}
我算什么为了适应这种配置的COM端口5+的USB-选项>串行适配器将显示为?我可以像DOS命令一样(在Windows设备管理器中像普通人一样)看到它们,但我不确定如何从诊断程序访问它们。
另外,很多USB串行适配器并没有实现所有的状态控制线(或者正确实施) – 2012-07-13 16:59:14