public void writeData(int len, byte[] to_send)
    {
    	//get_lock();
    	currline="";		//reset the receive buffer
    	for(int i = 0; i < currbuf.length; i++)
    		currbuf[i] = 0x00;
    	logText = "--> ["+ dump(len, to_send)+"]";
    	trytolog(logText);
    	//startreader();
    	this.expected_len = -1;
        this.read_len = 0;
        this.stx_seen = false;
        this.etx_seen = false;
        this.len_seen = false;
        /*
        this.serialPort.setDTR(true);
        this.serialPort.setRTS(true);
        this.serialPort.setInputBufferSize(512);
         */
    	try {
        	for(int i = 0; i< len; i++) {
        		output.write(to_send[i]);
        		output.flush();
        		timer(50);
        	}
        }catch (Exception e) {
            logText = "Failed to write data. (" + e.toString() + ")";
            trytolog(logText);
        }
    }