This README file is best viewed online.
You can download a pre-built driver package directly from our website.
There is documentation for each specific function listed below, but lets get started with a quick programming example for fun. This tutorial has already been set up for you at asynccom-windows/examples/tutorial/tutorial.c
.
Create a new C file (named tutorial.c) with the following code.
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <ntddser.h>
#include "asynccom.h"
int main(void)
{
HANDLE h = 0;
DWORD tmp;
unsigned char odata[] = "Hello world!";
unsigned char idata[20];
DCB mdcb;
BOOL success;
/* Open port 0 in a blocking IO mode */
h = CreateFile(L"\\\\.\\COM8", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (h == INVALID_HANDLE_VALUE) {
fprintf(stderr, "CreateFile failed with %d\n", GetLastError());
return EXIT_FAILURE;
}
memset(&mdcb, 0, sizeof(mdcb));
mdcb.DCBlength = sizeof(mdcb);
success = GetCommState(h, &mdcb);
if (!success)
{
printf("GetCommState failed! %d\n", GetLastError());
return EXIT_FAILURE;
}
mdcb.BaudRate = 115200;
mdcb.ByteSize = 7;
mdcb.Parity = NOPARITY;
mdcb.StopBits = ONESTOPBIT;
if (SetCommState(h, &mdcb) == FALSE) {
fprintf(stderr, "SetCommState failed with %d\n", GetLastError());
return EXIT_FAILURE;
}
PurgeComm(h, PURGE_TXCLEAR | PURGE_RXCLEAR);
WriteFile(h, odata, sizeof(odata), &tmp, NULL);
/* Read the data back in (with our loopback connector) */
ReadFile(h, idata, sizeof(idata), &tmp, NULL);
fprintf(stdout, "%s\n", idata);
return 0;
}
For this example I will use the Visual Studio command line compiler, but you can use your compiler of choice.
# cl tutorial.c
Now attach the included loopback connector.
# tutorial.exe
Hello world!
You have now transmitted and received data!
The Fastcom: Async Com has a maximum baud rate 40 Mhz, but throughput may be lower than that.
The Fastcom: Async Com cards have their baud rate configured using the standard Windows API, such as IOCTL_SERIAL_SET_BAUD_RATE.
To get a non-standard baud rate there are a couple variables you need to setup before you can achieve them.
First is the variable clock generator frequency and second is the variable sampling rate. The formula for determining a baud rate is as follows.
Baud Rate = Clock Rate / Sampling Rate / Integer Divisor.
The 'Integer Divisor' value is determined in the driver and as long as the rest of the formula allows for an integer divisor it can be ignored.
Here is an example of some values that will work. We would like a baud rate of 1 MHz so we find a combination of a clock rate of 16 MHz and a sampling rate of 16 that can be divided by an integer to end up with 1 MHz. Now if we configure these two values we will be able to achieve any supported rate we want.
1,000,000 = 16,000,000 / 16 / 1
Once you understand how to achieve a desired baud rate, you can use our examples to achieve whatever baud rates you need.
There are likely other configuration options you will need to set up for your own program. All of these options are described on their respective documentation page.
- Connect
- Clock Rate
- Echo Cancel
- External Transmit
- Frame Length
- Isochronous
- 9-Bit Protocol
- Read
- RS485
- RX Trigger
- Sample Rate
- TX Trigger
- Write
- Disconnect
- Windows Driver Kit (7.1.0 used internally to support XP)
- OS: Windows 7+
We follow Semantic Versioning when creating releases.
Copyright (C) 2019 Commtech, Inc.
Licensed under the MIT license.