outportb函数与inportb函数是什么
发表于:2025-02-19 作者:千家信息网编辑
千家信息网最后更新 2025年02月19日,outportb函数与inportb函数是什么,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。outportb函数是属于Turbo C
千家信息网最后更新 2025年02月19日outportb函数与inportb函数是什么
outportb函数与inportb函数是什么,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
outportb函数是属于Turbo C(TC)语言库函数,这是一个输出到硬件端口的函数,似乎是当年学习C语言的时候用这个东西,现在用的C++里面没有这个函数,今天在做一个软件说明书时,看到这个函数,在网上搜索了下,放在这里,以备大家使用时查明:
-----------------------------------------------------------------
outportb函数
函数原型: void outportb(unsigned char port, unsigned char value)
函数功能: 向port地址的接口输出value
函数返回:
函数说明: port 端口地址,value要输出的8位数
所属文件:
程序例:
#include#include int main(void) { int value = 64; int port = 0; outportb(port, value); printf("Value %d sent to port number %d\n", value, port); return 0; }
---------------------------------------------------------------------------------------------
另附上与之对应的inportb函数的说明
函数名: inportb
功 能: 返回从指定硬件端口读入的一个8位二进制(一个字节)。
用 法: int inportb(int port);
程序例:
#include#include int main(void) { int value ; int port =0x210; value=inportb(port); printf("port 0x%x sent Value is%d\n", port,value ); return 0; }
而在C++中,没有像inportb/outportb,inportw/outputw专门的端口读写函数
但可以用::CREATEFILE(。。。。)
例子:
BOOL CSerialPort::InitPort(CWnd* pPortOwner, // the owner (CWnd) of the port (receives message) UINT portnr, // portnumber (1..4) UINT baud, // baudrate char parity, // parity UINT databits, // databits UINT stopbits, // stopbits DWORD dwCommEvents, // EV_RXCHAR, EV_CTS etc UINT writebuffersize) // size to the writebuffer { assert(portnr > 0 && portnr < 5); assert(pPortOwner != NULL); // if the thread is alive: Kill if (m_bThreadAlive) { do { SetEvent(m_hShutdownEvent); } while (m_bThreadAlive); TRACE("Thread ended\n"); } // create events if (m_ov.hEvent != NULL) ResetEvent(m_ov.hEvent); m_ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (m_hWriteEvent != NULL) ResetEvent(m_hWriteEvent); m_hWriteEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (m_hShutdownEvent != NULL) ResetEvent(m_hShutdownEvent); m_hShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // initialize the event objects m_hEventArray[0] = m_hShutdownEvent; // highest priority m_hEventArray[1] = m_ov.hEvent; m_hEventArray[2] = m_hWriteEvent; // initialize critical section InitializeCriticalSection(&m_csCommunicationSync); // set buffersize for writing and save the owner m_pOwner = pPortOwner; if (m_szWriteBuffer != NULL) delete [] m_szWriteBuffer; m_szWriteBuffer = new char[writebuffersize]; m_nPortNr = portnr; m_nWriteBufferSize = writebuffersize; m_dwCommEvents = dwCommEvents; BOOL bResult = FALSE; char *szPort = new char[50]; char *szBaud = new char[50]; // now it critical! EnterCriticalSection(&m_csCommunicationSync); // if the port is already opened: close it if (m_hComm != NULL) { CloseHandle(m_hComm); m_hComm = NULL; } // prepare port strings sprintf(szPort, "COM%d", portnr); sprintf(szBaud, "baud=%d parity=%c data=%d stop=%d", baud, parity, databits, stopbits); // get a handle to the port m_hComm = CreateFile(szPort, // communication port string (COMX) GENERIC_READ | GENERIC_WRITE, // read/write types 0, // comm devices must be opened with exclusive access NULL, // no security attributes OPEN_EXISTING, // comm devices must use OPEN_EXISTING FILE_FLAG_OVERLAPPED, // Async I/O 0); // template must be 0 for comm devices if (m_hComm == INVALID_HANDLE_VALUE) { // port not found delete [] szPort; delete [] szBaud; return FALSE; } // set the timeout values m_CommTimeouts.ReadIntervalTimeout = 1000; m_CommTimeouts.ReadTotalTimeoutMultiplier = 1000; m_CommTimeouts.ReadTotalTimeoutConstant = 1000; m_CommTimeouts.WriteTotalTimeoutMultiplier = 1000; m_CommTimeouts.WriteTotalTimeoutConstant = 1000; // configure if (SetCommTimeouts(m_hComm, &m_CommTimeouts)) { if (SetCommMask(m_hComm, dwCommEvents)) { if (GetCommState(m_hComm, &m_dcb)) { m_dcb.fRtsControl = RTS_CONTROL_ENABLE; // set RTS bit high! if (BuildCommDCB(szBaud, &m_dcb)) { if (SetCommState(m_hComm, &m_dcb)) ; // normal operation... continue else ProcessErrorMessage("SetCommState()"); } else ProcessErrorMessage("BuildCommDCB()"); } else ProcessErrorMessage("GetCommState()"); } else ProcessErrorMessage("SetCommMask()"); } else ProcessErrorMessage("SetCommTimeouts()"); delete [] szPort; delete [] szBaud; // flush the port PurgeComm(m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT); // release critical section LeaveCriticalSection(&m_csCommunicationSync); TRACE("Initialisation for communicationport %d completed.\nUse Startmonitor to communicate.\n", portnr); return TRUE; }
关于outportb函数与inportb函数是什么问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。
函数
端口
问题
输出
地址
更多
硬件
程序
语言
C++
帮助
解答
易行
简单易行
东西
二进制
位数
例子
内容
功能
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
戴尔服务器大小
大学生写论文的数据库
八种方法 网络安全 漫画
java开源数据库
秦皇岛森雅网络技术
店账通怎么导出数据库
fil服务器怎么上架
云服务器动态ip白名单
在哪里可以租我的世界服务器
物联网服务器在哪里
天水市网络安全教育平台登录口
pubg手机版服务器繁忙怎么办
泸州网络技术专业
学校校园网络安全工作计划
各大网络安全产品
mc服务器穿墙
奇迹sf服务器改名
东营网络安全工作
软件开发前对客户的服务
宿迁智能化服务器技术指导
软件开发订单商品id如何确定
网络安全标准化
服务器管理员面试自我介绍
车联网使用的网络技术
伊春市趣玩网络技术有限公司旗下
网络安全执法工作遇到的问题
网络安全法宣传要求
戴尔服务器主板电路图纸
设计和实现某系统数据库
辽宁网络安全调查