我正在使用內部軟件工具,該工具顯示&日誌格式化的診斷數據,這些數據是從我開發嵌入式軟件的產品的串行調試端口收集而來的。它是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