lau*_*ote 2 c usb serial-port dos turbo-c
我正在使用一个内部软件工具,显示和记录从我开发嵌入式软件的产品的串行调试端口收集的格式化诊断数据.这是在C和非常老.它是使用Borland Turbo-C v1.01(1990版权所有)构建的.如果可能的话,我宁愿修改而不是为现代环境重写工具.
我想一次从多个设备收集调试数据.我设想了几个通过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
}
Run Code Online (Sandbox Code Playgroud)
由于USB->串行适配器将显示为什么,我可以选择为COM端口5+调整这种配置?我可以通过DOS mode命令(和Windows设备管理器中的普通人一样)看到它们,但我不确定如何从诊断程序访问它们.
直接寻址I/O寄存器需要一个模拟传统COM端口行为的设备驱动程序.标准的Microsoft设备驱动程序执行此操作.但是你没有使用那个驱动程序,你有一个供应商特定的USB驱动程序.
这些驱动程序通过将自身连接到串行端口的标准winapi函数来模拟串行端口.像CreateFile(),SetCommConfig()等.这需要编写32位代码才能使用这些功能.他们不做的是模拟寄存器,以便DOS应用程序仍然可以正常工作,完成并完成.并且一般不能工作,DOS只支持4个COM端口,因此只使用了4组寄存器.COM5及更高版没有标准寄存器地址.
也许你可以找到一个带有驱动程序的USB模拟器仍然可以做到这一点.但我认为赔率非常低.相反,将您的90年代软件与90年代的硬件结合起来.购买一把拧入总线的老式PCI卡.这样标准的Microsoft驱动程序就可以运行.这些卡片上次我看起来(胖了一年前)仍然可用,虽然选择变得越来越苗条.或者从旧机器中挖出一个.
| 归档时间: |
|
| 查看次数: |
2679 次 |
| 最近记录: |