📄 serial.c
字号:
// MobyPalm
// Copyright (C) 2005 Olivier Burgard
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <PalmOS.h>
#include <SerialMgr.h>
#include "Serial.h"
#include "Common.h"
UInt16 portId;
Char szError[128];
Boolean serPortOpened = false;
BOOL SerialOpen(int baud) {
Err err;
Int16 paramSize;
UInt32 flags;
MemSet(szError,sizeof(szError),0);
err = SrmOpen(serPortCradleRS232Port /* port */, 9600, /* baud */ &portId);
flags = srmSettingsFlagBitsPerChar8;
paramSize = sizeof(flags);
err = SrmControl(portId, srmCtlSetFlags, &flags, ¶mSize);
SrmReceiveFlush(portId, 0);
if (err) {
// display error message here.
FrmCustomAlert(5000, GetSerialErrorText(err, szError), "", "");
serPortOpened = false;
} else
//record our open status in global.
serPortOpened = true;
return serPortOpened;
}
void SerialClose(void) {
if (serPortOpened) {
SrmClose(portId);
serPortOpened=false;
}
}
long SerialCheck(void) {
long n = -1;
if (serPortOpened)
if (SrmReceiveCheck(portId, &n) != errNone)
SrmClearErr(portId);
return n;
}
BOOL SerialRead(UInt8 *buf, int buflen, int timeout) {
Err err;
MemSet(szError,sizeof(szError),0);
if (serPortOpened) {
SrmReceive(portId, buf, buflen, timeout, &err);
if (err != errNone){
//FrmCustomAlert(5000, GetSerialErrorText(err, szError), "", "");
SrmClearErr(portId);
}
else
return true;
}
return false;
}
void SerialWrite(UInt8* buf, int buflen) {
Err err;
MemSet(szError,sizeof(szError),0);
if (serPortOpened) {
SrmSend(portId, buf, buflen, &err);
if (err != errNone) {
//FrmCustomAlert(5000, GetSerialErrorText(err, szError), "", "");
SrmClearErr(portId);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -