POS Device Communication Library via RS232 for STM32, other microcontrollers, and C programs
-
- STM32 series - Arduino - C/C++ Programs
-
- Support STM32, Arduino and other C/C++ Programs - Easily communicate with the POS device - Get complete transaction information - Adapt your program to various payment statuses - Callback and Non-blocking Mode Support
-
-
-
enum POS_TransactionResultTypeDef
: Result of Transaction, Params:- TRANSACTION_SUCCESS - TRANSACTION_CANCEL - TRANSACTION_WRONG_PASSWORD - TRANSACTION_POS_TIMEOUT - TRANSACTION_NETWORK_ERROR - TRANSACTION_INSUFFICIENT_FUNDS - TRANSACTION_TIMEOUT - TRANSACTION_WRONG_RESULT - TRANSACTION_PACKET_ERROR
-
enum POS_StatusTypeDef
: Status of POS Operation, Params:- POS_ERROR - POS_OK
-
struct POS_TransactionInfoTypeDef
: Transaction Parameters, Params:/* ...... Transaction Date ..... */ uint16_t Year; uint8_t Month; uint8_t Day; /* ...... Transaction Time ..... */ uint8_t Hour; uint8_t Minute; uint8_t Second; /* ............................. */ uint32_t Fee; char CardNumber[]; char ReferenceNumber[]; char TrackingNumber[]; char MerchantID[]; char TerminalID[];
-
struct POS_TypeDef
: POS Handle Type
- None
- None
/* ..................... POS - Transaction ..................... */
POS_StatusTypeDef POS_SendTransaction(POS_TypeDef *POS, char *TotalFee, uint32_t Timeout);
/* ..................... POS - ISR Handler ..................... */
void POS_UART_ISRHandler(POS_TypeDef *POS, uint8_t uData);
void POS_TimingHandler(POS_TypeDef *POS);
/* ...................... POS - Callback ....................... */
void POS_TransactionCallback(POS_TransactionResultTypeDef TransactionResult, POS_TransactionInfoTypeDef TransactionInfo);
#include "main.h"
#include "usart.h"
POS_TypeDef MainPOS;
void UART_RxISR(uint8_t ReceivedValue)
{
POS_UART_ISRHandler(&MainPOS, ReceivedValue);
}
void POS_TransactionCallback(POS_TransactionResultTypeDef TransactionResult, POS_TransactionInfoTypeDef TransactionInfo)
{
// Some code to get transaction status and parameters
}
int main()
{
while (1)
{
POS_TimingHandler(&MainPOS);
}
}
int main()
{
while (1)
{
POS_SendTransaction(&MainPOS, Fee, 30000);
POS_TimingHandler(&MainPOS);
}
}
#include "main.h"
#include "usart.h"
#include "gpio.h"
#include <stdio.h>
#include "pos_terminal.h"
/* ----------------- Global Variable ------------------- */
uint8_t uartData = 0;
char Fee[] = "50000";
char msg[300] = { 0 };
POS_TypeDef MainPOS;
/* ----------------- USART Interrupt ------------------- */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart2, &uartData, 1);
POS_UART_ISRHandler(&MainPOS, uartData);
}
/* ------------------- POS Callback -------------------- */
void POS_TransactionCallback(POS_TransactionResultTypeDef TransactionResult, POS_TransactionInfoTypeDef TransactionInfo)
{
switch (TransactionResult)
{
case TRANSACTION_SUCCESS:
{
sprintf(msg, "Transaction Success:\nFee:%lu\nDate:%d:%d:%d\nTime:%d:%d:%d\nCard Number:%s\nReference Number:%s\nTracking Number:%s\nTerminal:%s\n", TransactionInfo.Fee, TransactionInfo.Year, TransactionInfo.Month, TransactionInfo.Day, TransactionInfo.Hour, TransactionInfo.Minute, TransactionInfo.Second, TransactionInfo.CardNumber, TransactionInfo.ReferenceNumber, TransactionInfo.TrackingNumber, TransactionInfo.TerminalID);
HAL_UART_Transmit(&huart1, (uint8_t*)msg, strlen(msg), 100);
}
break;
case TRANSACTION_CANCEL:
{
HAL_UART_Transmit(&huart1, (uint8_t*)"Transaction Cancel\n", strlen("Transaction Cancel\n"), 100);
}
break;
case TRANSACTION_WRONG_PASSWORD:
{
HAL_UART_Transmit(&huart1, (uint8_t*)"Wrong Password\n", strlen("Wrong Password\n"), 100);
}
break;
case TRANSACTION_NETWORK_ERROR:
{
HAL_UART_Transmit(&huart1, (uint8_t*)"Network Error\n", strlen("Network Error\n"), 100);
}
break;
case TRANSACTION_INSUFFICIENT_FUNDS:
{
HAL_UART_Transmit(&huart1, (uint8_t*)"Insufficient Funds\n", strlen("Insufficient Funds\n"), 100);
}
break;
case TRANSACTION_POS_TIMEOUT:
{
HAL_UART_Transmit(&huart1, (uint8_t*)"POS Timeout\n", strlen("POS Timeout\n"), 100);
}
break;
case TRANSACTION_TIMEOUT:
{
HAL_UART_Transmit(&huart1, (uint8_t*)"Transaction Timeout\n", strlen("Transaction Timeout\n"), 100);
}
break;
case TRANSACTION_WRONG_RESULT:
{
HAL_UART_Transmit(&huart1, (uint8_t*)"Transaction Wrong Error\n", strlen("Transaction Wrong Error\n"), 100);
}
break;
case TRANSACTION_PACKET_ERROR:
{
HAL_UART_Transmit(&huart1, (uint8_t*)"Packet Error\n", strlen("Packet Error\n"), 100);
}
break;
default:
break;
}
}
/* ----------------------------------------------------- */
int main(void)
{
/* Initialize SPI, GPIO, and requirement hardware */
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
/* ---------------------------------------------- */
MainPOS.UARTx = &huart2;
HAL_UART_Receive_IT(&huart2, &data, 1);
HAL_UART_Transmit(&huart1, (uint8_t *)"Hello, <Push Key to send transaction>\n", strlen("Hello, <Push Key to send transaction>\n"), 100);
while (1)
{
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == 0)
{
POS_SendTransaction(&MainPOS, Fee, 30000);
}
POS_TimingHandler(&MainPOS);
}
}
- STM32F1
- Arduino
- AVR