Giter VIP home page Giter VIP logo

asynccom-windows's Introduction

asynccom-windows

This README file is best viewed online.

Installing Driver

Downloading Driver Package

You can download a pre-built driver package directly from our website.

Quick Start Guide

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!

Using The Serial Port

Setting Baud Rate

Max Supported Speeds

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.

API Reference

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.

FAQ

Build Dependencies

  • Windows Driver Kit (7.1.0 used internally to support XP)

Run-time Dependencies

  • OS: Windows 7+

API Compatibility

We follow Semantic Versioning when creating releases.

License

Copyright (C) 2019 Commtech, Inc.

Licensed under the MIT license.

asynccom-windows's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.