Syntax
long OseComm(
long sessionID,
int terminateKey,
const char *appVersion,
pOnOseCommInfo OnOseCommInfo
);
Parameters
- sessionID
-
[in] The communication identification number for the session.
- The valid range is from 0 to 16777215 (0x000000 to 0xFFFFFF).
- If -1 is specified, the value of the random number generated in the terminal will be used.
Note:
- The value specified in this parameter is used for the "Terminal ID" of the [Advanced filename] setting in the [Received file(s) dialog] of the OseComm32 utility. Note that it is not the value of the Terminal ID in the System menu.
- To use the value of the Terminal ID in the System menu as the ID number, use the GetTerminalId function to get the value. In this case, you need to set the ID number for each device using Terminal ID.
- If you want to use the serial number of the terminal as the ID number, use GetSerialNo function to get the value.
- terminateKey
-
[in] When this key is pressed the session is aborted.
- [ANY_KEYS_ABORT] - Abort when any key is pressed.
- ['0'-'9' or other key ID] - Abort when a specific key is pressed.
- The SHIFT key, power key, and side key do not interrupt.
- appVersion
-
[in] Specify the character string to be returned when the version number is requested from the connection destination.
- Do not use spaces (0x20).
- The character string after the space is invalid.
- OnOseCommInfo
-
[out] Callback function that gets the status, error, and progress information.
- NULL if no callback function is used.
- [Callback function prototype]:
void OnOseComInfo(int status, int errorsuccess, int progress, const char *info);
status -
[out] Stores the type of communication session.
Value Description STAT_GET_TIME_DATE Get date and time STAT_SET_TIME_DATE Set date and time STAT_GET_OS_VERSION Get OS Version STAT_GET_APPL_VERSION Get Application Version STAT_XMIT_FILE_TO_PC Send file to PC. STAT_RECV_FILE_FROM_PC Receive file from terminal. STAT_LIST_FILES List files on the terminal. STAT_DELETE_FILES Delete files from the terminal. - errorsuccess
-
[out] The session status is stored.
- [SUCC_COMPLETE]completes the session normally.
- Or take one of the following [Return value].
- progress
-
[out] When sending and receiving files, the progress is stored as a value from 0 to 100.
- For other sessions, 0 is stored.
- info
-
[out] When sending or receiving a file, the file name is stored.
- For other sessions, 0 is stored.
Return value
Value | Description |
---|---|
COMM_OK | Communication OK. |
ERR_PR_NO_RESPONSE | No response. |
ERR_PR_CRC | CRC-16 error. |
ERR_PR_CMD_MISMATCH | Wrong command received. |
ERR_PR_FRAME_LENGTH | Frame length error. |
ERR_PR_SESSION_ID | Session ID mismatch. |
ERR_PR_SENDING_FRAME | Error sending frame. |
ERR_PR_OPEN_FILE | Cannot open or create the requested file. |
ERR_PR_READ_FROM_FILE | Cannot read from file. |
ERR_PR_WRITE_TO_FILE | Cannot write to file |
ERR_PR_WRONG_BLOCK | Requested the wrong block number. |
ERR_PR_FILE_SIZE | Error in file sizes. |
ERR_PR_POLL_COMMAND | Unexpected poll command. |
ERR_PR_FILE_UNAVAILABLE | File cannot be found in the terminal. |
ERR_PR_LINE_BUSY | An other terminal is already communicating. |
ERR_PR_TIME_DATE | Error in the time or date when it is being set. |
ERR_PR_DELETE_FILE | Error deleting file. |
ERR_PR_USER_ABORT | User aborted the protocol. |
Remarks
Uses a new protocol to transmit and receive one or more complete files through a serial communications port.
Requirements
Header file:
lib.hLibrary file:
libSTARTUPOPH5000.a
Sample
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "lib.h"
void sampleMain(void);
void OnOseComInfo(int status, int errorsuccess, int progress, const char *info);
bool BT_Connect(char *BD_address);
void BT_Disconnect(void);
char *bd_address = "00126AFFE131"; //BD address of PC's Bluetooth adapter
static bool g_BT_Opened = false;
void main(void)
{
while(1){
printf("\n## OseComm sample ##\n");
printf(" Press ENT to start\n");
while(1){
if (kbhit()){
if (getchar() == ENT_KEY){
sampleMain();
break;
}
}
Idle();
}
}
}
void sampleMain(void)
{
char serialNoText[17];
long serialNo;
bool aborted = false;
long result;
printf(" <Press BS to abort>\n");
printf(" Bluetooth started\n");
// Wait for Bluetooth connection
while (!BT_Connect(bd_address)){
if (kbhit()){
if (getchar() == BS_KEY){
aborted = true;
printf(" ->Aborted\n");
break;
}
}
Idle();
}
if (aborted){
BT_Disconnect();
return;
}
printf(" ->Connected\n");
// Do OseComm protocol while Bluetooth is connected
printf(" OseComm started\n");
//Use serial no as a session ID.
GetSerialNo(serialNoText);
serialNo = atol(serialNoText);
result = OseComm(serialNo, BS_KEY, "SAMPLE1.0", OnOseComInfo);
if (result == COMM_OK){
printf(" ->success\n");
}else if (result == ERR_PR_USER_ABORT){
printf("\n ->aborted\n");
}else{
printf(" ->error(%ld)\n", result);
}
BT_Disconnect();
return;
}
void OnOseComInfo(int status, int errorsuccess, int progress, const char *info)
{
switch (status)
{
case STAT_GET_TIME_DATE:
printf(" > get time\n");
break;
case STAT_SET_TIME_DATE:
printf(" > set time\n");
break;
case STAT_GET_OS_VERSION:
printf(" > OS version\n");
break;
case STAT_GET_APPL_VERSION:
printf(" > APP version\n");
break;
case STAT_XMIT_FILE_TO_PC:
if (errorsuccess == SUCC_COMPLETE){
printf("\n");
}else if (errorsuccess == 0){
printf(" > S:%s:%d\r", info, progress);
}else if (errorsuccess != 0){
printf("\n -->Error(%d)\n", errorsuccess);
}
break;
case STAT_RECV_FILE_FROM_PC:
if (errorsuccess == SUCC_COMPLETE){
printf("\n");
}else if (errorsuccess == 0){
printf(" > R:%s:%d\r", info, progress);
}else if (errorsuccess != 0){
printf("\n -->Error(%d)\n", errorsuccess);
}
break;
case STAT_LIST_FILES:
//printf(" > list file\n");
break;
case STAT_DELETE_FILES:
printf(" > delete file\n");
break;
default:
printf(" > unknown:%d\n", status);
break;
}
}
bool BT_Connect(char *BD_address)
{
if (GetConnectionStatus(COM3) != COM_STATE_CONNECT){
if (!g_BT_Opened){
// Open COM3 (Bluetooth SPP/Master)
SetDefault(COM3);
BltSetConnectAddress(BD_address);
if (ComOpen(COM3) == OK){
BltWaitAcceptStart();
g_BT_Opened = true;
}
}
return false;
}else{
BltWaitAcceptEnd(TRUE);
return true;
}
}
void BT_Disconnect(void)
{
if (g_BT_Opened){
BltWaitAcceptEnd(TRUE);
ComClose(COM3);
g_BT_Opened = false;
}
}
Last updated: 2021/06/07