API FUsion 4 NCDComponent


i’m trying to write and read I2C sensors through the I2C port on the Fusion 4 board with API structure.
I want to use VB.net from visualstudio 2017, as i used this in the past.
I’m not a programmer, so i’m really learning.

the idea is to control a fan speed according to the temperature. I want to read and act every 5 to 10 seconds.
I use the HYT939 sensor for temperature, PCA9531 2-Channel 8-bit PWM with 8 Outputs & GPIO I2C LED Dimmer for controlling the fan ( This works, already tested it), and a 1 channel relay controller: MCP23008 I2C Controlled Mechanical DPDT Relay for controlling the power to the relais.

I have learned about the API protocol, and the meaning of checksum etc.
But now is my question how to accurate send an API command to the fusion board using VB.Net and using the NCDComponent.dll

I managed to get it but i still have question if it is correct or not.
The code: NcdComponent1.WriteBytesAPI(188, 51, 3, 64, 9, 1, 0, 238) will put the relais on.
But: Do i need to write the full API code?: 170, 7, 188, 51, 3, 64, 9, 1, 0, 238 or do i need to right only 188, 51, 3, 64, 9, 1, 0 and do i need to at the checksum or not?

With 170, 7 added i don’t get response, without it seems to work but not always. Is there already 170, 7 inserted with in the WryteBytesAPI code?

Also: When using AnyI2C i can lookup and see what the W and R values are in API Command mode (dec). But for HYT939 sensor this seems to be a bit more complex then just writing one line. Also, is there a conversion table for displaying the temperature / humidity with the values getting returned by the sensor?

This is my code for just controllig the relais on and off (And also changes some button names )

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
    NcdComponent1.UsingComPort = "false"
    If Button2.Text = "OFF" Then
        NcdComponent1.OpenPort() : Button2.Text = "LIVE"
        Button2.Text = "LIVE"
        Button2.ForeColor = Color.White
        Button2.BackColor = Color.Navy
        **NcdComponent1.WriteBytesAPI(188, 51, 3, 64, 9, 1, 0, 238)**
        Button2.Text = "OFF"
        Button2.ForeColor = Color.Black
        Button2.BackColor = Color.Gainsboro
    End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    **NcdComponent1.WriteBytesAPI(188, 51, 3, 64, 10, 0, 0, 237)**
End Sub

End Class

This is one simple read of temperature and humidity with HYT939 sensor in AnyI2C with API code Dec enabled.
How do i send this in an API write command and how do i read it? Because here a value will be returned to my VB.net program.

I just need to “see” it, so that i understand the way of using the code: WriteBytesApi …

W: 170 6 188 51 2 80 128 0 113
W: 188 51 2 80 128 0
R: 85
W: 170 6 188 51 2 80 0 0 241
W: 188 51 2 80 0 0
R: 85
W: 170 5 188 51 1 81 4 244
W: 188 51 1 81 4
R: 81 185 94 145

If there are more tutorials on using API with the NCDComponent.dll command, then please let me know. :slight_smile:

Thank you.

There is a bug of anyi2c output of API write. It duplicated the api frame and raw data.
To use WriteBytesAPI, no “170 x” is needed as it will packed by WriteBytesAPI
I would suggest that use AnyI2CLib.dll instead of use NCD Component.dll directly, as it wrapped that I2C ready and ready already. Or you can copy the code of I2Cread and write directly to your project. It does take several commands to read the temperature from 939 correctly.

That about the API frame and RAW data in AnyI2C output i already noticed. I actually don’t see it as an “bug”, it kind of helped me understand a bit.

So the actually fully code for reading an 939 would be:

W:170 6 188 51 2 80 128 0 113
R: 85
W:170 6 188 51 2 80 0 0 241
R: 85
W:170 5 188 51 1 81 4 244
R: 81 185 94 145

And the checksum must always be added, right?

I have created a post to help, but I need to spend more time on this topic. All the code you need is in this post, but there is a lot of junk too, so please look through it carefully. I will work with Xu to get a working implementation together in the comming weeks:

We will be posting Base Station on GitHub in the coming weeks as well, which will show all of this working.


Is there any update on this topic? Are there some easier ways now to do this?

Thank you.

Source code for Base Station is available for download, please follow this thread for a download link: