Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

trkall / T-Diagnostics

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • T-Diagnostics
  • src
  • com
  • tDiagnostics
  • communication
  • InitiateConnection.java
Find file
BlameHistoryPermalink
  • Tref's avatar
    upload structured project · bd8c3f69
    Tref committed 4 years ago
    bd8c3f69
InitiateConnection.java 1.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
package com.tDiagnostics.communication;

import com.fazecast.jSerialComm.SerialPort;
import com.tDiagnostics.communication.handler.ConnectionHandler;


import static com.fazecast.jSerialComm.SerialPort.NO_PARITY;

public class InitiateConnection {
    public static boolean startComms(SerialPort comPort, ConnectionHandler con){
        System.out.println("START_startComms");
        comPort.setBaudRate(9600);
        comPort.setNumDataBits(8);
        comPort.setParity(NO_PARITY);
        comPort.setNumStopBits(1);
        comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
        con.sendZeroWith5Bd(comPort);//start
        //comPort.clearDTR();//data

        //Thread.sleep(200);

        int par = 1;
        int buf = con.controlUnit;
        Integer funcs[] = new Integer[7];
        for(int i=6;i>=0;i--) {
            if(buf >= Math.pow(2,i)) {
                buf -= Math.pow(2,i);
                funcs[i] = 1;
                par = par ^ 1;
            }else {
                funcs[i] = 0;
            }
        }
        for(int x : funcs) {
            if(x == 0)
                con.sendZeroWith5Bd(comPort);
            else
                con.sendOneWith5Bd(comPort);
        }
        if(par == 0)
            con.sendZeroWith5Bd(comPort);
        else
            con.sendOneWith5Bd(comPort);
        con.sendOneWith5Bd(comPort);

        //comPort.setDTR();
        return true;
    }
}